<template>
  <div class="login-container"
       :style="{'background-image': `url(${require('@/assets/bg.png')})`,'background-repeat':'no-repeat','background-size':'100% 100%'}"
  >
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on"
             label-position="left"
    >

      <div class="title-container">
        <h3 class="title">登录</h3>
      </div>

      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon icon-class="user"/>
        </span>
        <el-input
          ref="username"
          v-model="loginForm.username"
          placeholder="用户名"
          name="username"
          type="text"
          tabindex="1"
        />
      </el-form-item>

      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password"/>
        </span>
        <el-input
          :key="passwordType"
          ref="password"
          v-model="loginForm.password"
          :type="passwordType"
          placeholder="密码"
          name="password"
          tabindex="2"
          @keyup.enter.native="handleLogin"
        />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"/>
        </span>
      </el-form-item>
<!--      <el-form-item prop="line">-->
<!--        <span class="svg-container">-->
<!--          <svg-icon icon-class="line"/>-->
<!--        </span>-->
<!--        <el-select v-model="loginForm.line" popper-class="login-option" placeholder="请选择产线">-->
<!--          <el-option-->
<!--            v-for="item in options"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value"-->
<!--          >-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->

      <el-button :loading="loading" type="primary" style="width:100%;margin:12px 0;font-size: 20px;height: 36px;padding: 0px;"
                 @click.native.prevent="handleLogin"
      >登录
      </el-button>
      <!--      <el-row type="flex" style="justify-content: space-between">-->
      <!--                <el-link type="info" @click="$router.push({path:'/workOrderSys/orderDetail',query:{name:scope.row.title}})">忘记密码</el-link>-->
      <!--        <el-link type="info" @click="$router.push({path:'/register'})">去注册</el-link>-->
      <!--      </el-row>-->
    </el-form>
  </div>
</template>

<script>

import {getTemplateBody} from "@/api/table";

export default {
  name: 'Login',
  data() {
    const validateUsername = (rule, value, callback) => {
      callback()
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 3) {
        callback(new Error('密码不小于6位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: '',
        line: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined,
      options: [{
        value: '选项1',
        label: '10kV线路断路器产线'
      }, {
        value: '选项2',
        label: 'ZW32产线'
      }, {
        value: '选项3',
        label: '开关柜'
      }, {
        value: '选项4',
        label: '充气柜'
      }]
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || '/' })
            this.loading = false
            getTemplateBody()
          }).catch(() => {
            this.loading = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #283443;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

.login-option{
  li{
    font-size: 18px;
  }
}
/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 36px;
    width: 85%;
    input {
      font-size: 18px;
      &::placeholder { /* 大部分现代浏览器 */
        color: #909399;
      }

      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      //color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 18px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg: #DBE5FA;
$dark_gray: #303133;
$light_gray: #303133;

.login-option{
  font-size: 18px;
}
.login-container {
  //background-image:url(@/assets/404_images/404_cloud.png);
  ::v-deep.el-form-item__error {
    height: 18px;
    font-size: 16px !important;
  }

  .svg-icon {
    font-size: 24px;
  }

  .el-form-item {
    height: 36px;
    line-height: 36px;
    background-color: #C5CEE1;

    .el-select {
      font-size: 18px;
      height: 64px;
      width: calc(100% - 42px);
      > .el-input{
        background-color: black!important;
        ::v-deep .el-input__inner{
          background: transparent!important;
          width: 10000px;
          font-size: 18px!important;
        }
      }
    }

    .el-input {
      ::v-deep input {
        background-color: transparent;
        padding: 0;
        height: 30px;
      }

      ::v-deep input:-webkit-autofill,
      ::v-deep input:-webkit-autofill:hover,
      ::v-deep input:-webkit-autofill:focus,
      ::v-deep input:-webkit-autofill:active {
        -webkit-transition-delay: 99999s;
        -webkit-transition: color 99999s ease-out, background-color 99999s ease-out;
      }

      height: 36px;
      line-height: 36px;
      font-size: 18px;
    }
    margin-bottom: 32px;
  }

  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: absolute;
    width: 320px;
    max-width: 100%;
    top:30%;
    left: calc(75vw - 260px);
    //padding: 300px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 0px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 42px;
    height: 48px;
    > svg {
      font-size: 20px;
    }

    display: inline-block;
  }

  .title-container {
    position: relative;
    .title {
      font-size: 26px;
      color: #0099ff;
      margin: 0px 0px 20px auto;
      text-align: left;
      font-weight:normal;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 4px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}

</style>
